package utils

import (
	"fmt"
	"net"
)

func PrivateIPV4() (net.IP, error) {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return nil, err
	}
	for _, addr := range addrs {
		ipNet, ok := addr.(*net.IPNet)
		if !ok || ipNet.IP.IsLoopback() {
			continue
		}
		ip := ipNet.IP.To4()
		if ip == nil {
			break
		}
		return ip, nil
	}
	return nil, fmt.Errorf("no private ip address")
}
